#include "DHT11.h"

using namespace model;

DHT11::DHT11(const DataModel &model_) {
  auto &d = model_.data;
  h.integral = d[4];
  h.decimal = d[3];
  t.integral = d[2];
  t.decimal = d[1];
}

auto DHT11::construct(const DataModel &model) -> Option {
  auto &d = model.data;
  auto ok = ((d[4] + d[3] + d[2] + d[1]) & 0xFF) == d[0];
  if (!ok) {
    return {};
  }
  return DHT11(model);
}
